package com.loan.controller.app.bank;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.system.domain.BankEntity;
import com.loan.system.domain.CompanyEntity;
import com.loan.system.domain.PayBankEntity;
import com.loan.system.domain.vo.ExamineUserVo;
import com.loan.system.service.PayBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiguang
 * @date 2022年09月15日 22:01
 */
@Validated
@Api(value = "支付银行管理", tags = {"支付银行管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/payBank")
public class PayBankController extends BaseController {

    private final PayBankService payBankService;

    /**
     * 获取支付银行列表
     */
    @ApiOperation("获取收款银行列表")
    //@SaCheckPermissio("app:payBank:list")
    @GetMapping("/page")
    public TableDataInfo<PayBankEntity> list(PayBankEntity entity, PageQuery pageQuery) {
        return payBankService.selectPageList(entity, pageQuery);
    }

    @ApiOperation("获取收款银行卡列表")
    //@SaCheckPermissio("app:apply:list")
    @GetMapping("/list")
    public Result<List<PayBankEntity>> getList() {
        return Result.ok(payBankService.getList());
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    //@SaCheckPermissio("app:payBank:query")
    @GetMapping(value = {"/{id}"})
    public Result<PayBankEntity> getInfo(@ApiParam("ID") @PathVariable(value = "id", required = false) Long id) {
        if (ObjectUtil.isNotNull(id)) {
            return Result.ok(payBankService.selectPayBankById(id));
        }
        return Result.ok();
    }

    /**
     * 新增支付银行卡
     */
    @ApiOperation("新增支付银行卡")
    //@SaCheckPermissio("app:payBank:add")
    @Log(title = "新增支付银行卡", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody PayBankEntity entity) {
        return toAjax(payBankService.addPayBank(entity));
    }

    /**
     * 修改支付银行卡
     */
    @ApiOperation("修改支付银行卡")
    //@SaCheckPermissio("app:payBank:update")
    @Log(title = "修改支付银行卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody PayBankEntity entity) {
        return toAjax(payBankService.updatePayBank(entity));
    }

    /**
     * 删除支付银行卡
     */
    @ApiOperation("删除支付银行卡")
    //@SaCheckPermissio("app:payBank:remove")
    @Log(title = "删除支付银行卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(payBankService.deletePayBankById(id));
    }

    /**
     * 状态修改
     */
    @ApiOperation("状态修改")
    //@SaCheckPermissio("app:payBank:edit")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public Result<Void> changeStatus(@RequestBody PayBankEntity entity) {
        return toAjax(payBankService.updateStatus(entity));
    }
}
